<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>库管管理</title>
<jsp:include page="../../import.jsp" flush="true" />
<jsp:include page="../assParking/assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->
</head>
<body class="iframeBody">
<div class="Wrapper">
<div>
<div id="pageInTab" class="pageInTab">
	<!-- 页签1：优车管理 -->
	<div tabid="tabA" title="库管管理" selected="true">
		<div class="searchArea">
			<!-- 搜索表单开始 -->
			<form id="searchBar">
				<div class="fieldset1 clearFix">
					<div class="FXBR">
						<div class="fieldBox">
							<div class="label">客户名称</div>
							<div class="field">
								<input type="text" id="cstNm" name="cstNm" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">支付表号</div>
							<div class="field">
								<input type="text" id="paySchNo" name="paySchNo" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">处置状态</div>
							<div class="field">
								<select name="dealStsCd" id="dealStsCd" ligerui="width: 160">
									<option value=" " selected>请选择</option>
									<c:forEach items="${dealStsList }" var="deal">
										<option value="${deal.key }">${deal.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">评估状态</div>
							<div class="field">
								<select name="evalStatusCd" id="evalStatusCd" ligerui="width: 160">
									<option value=" " selected>请选择</option>
									<c:forEach items="${evalStsList }" var="eval">
										<option value="${eval.key }">${eval.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">入库状态</div>
							<div class="field">
								<select name="isEnter" id="isEnter" ligerui="width: 160">
									<option value=" " selected>请选择</option>
									<option value="0">未入库</option>
									<option value="1">已入库</option>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">出库状态</div>
							<div class="field">
								<select name="isOut" id="isOut" ligerui="width: 160">
									<option value=" " selected>请选择</option>
									<option value="0">未出库</option>
									<option value="1">已出库</option>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">入库时间</div>
							<div class="field">
								<input type="text" id="minEnterTm" name="minEnterTm" class="ui-datepicker" ligerui="width: 160" value="">
								至
								<input type="text" id="maxEnterTm" name="maxEnterTm" class="ui-datepicker" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">出库时间</div>
							<div class="field">
								<input type="text" id="minOutTm" name="minOutTm" class="ui-datepicker" ligerui="width: 160" value="">
								至
								<input type="text" id="maxOutTm" name="maxOutTm" class="ui-datepicker" ligerui="width: 160" value="">
							</div>
						</div>
					</div>
					<!-- 隐藏当前选中的拖车主表ID和明细表ID信息 -->
					<div class="fieldBox" style="display:none;">
						<div class="field">
							<input name="tcMasterId" id="tcMasterId" type="text" class="ui-textbox" value="${tcMasterId}">
							<input name="tcDetailId" id="tcDetailId" type="text" class="ui-textbox" value="${tcDetailId}">
						</div>
					</div>
					
					<div class="clearFix"></div>
					
					<!-- 表单按钮 -->
					<div class="btnsBox formBtns notRight">
						<span id="searchBtn" class="sq-button-round">查询</span>
						<span id="clearBtn" class="sq-button-round">清空</span>
						<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
						<%--<span id="downBtn" class="sq-button-round" onclick="downloadBtnEvent();">导出Excel</span>--%>
		            </div>
				</div>
			</form>
			<!-- 搜索表单结束 -->
		</div>
		<!-- 列表显示块 -->
		<div id="ligergrid1" class="sq-grid"></div>
		
	</div>
	<!-- 页签2：流程跟踪 -->
	<div tabid="tabB" title="流程跟踪" id="tabBId" style="dis">
		<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
	</div>
</div>
</div>
</div>
<script type="text/javascript">
	var pageInApp={
		flag:false //tab页验证关闭
	};//to下一级子窗口 接口
	var pageInTab=null;//页签
	var loadedTabs=[];//页签
	var grid = null;
	$(function () {
	    initForm();//初始化表单
	    initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    initTab();//初始化页签
	    searchBtnEvent();//查询按钮事件
	    clearBtnEvent();//清空按钮事件
	});
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url:'<%=path%>/ass/assTrailCarM/warehouseInitList.do',
			method:'get',
			parms:getSearchParams(),
			columns:[
				{ display: '支付表号', name: 'paySchNo', minWidth: 180 , align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '';
						h='<a href="javascript:payDetail(';
                        h+="'"+rowdata.prjPrdDtlId+"',"; //项目产品明细信息表ID
                        h+="'"+rowdata.paySchId+"',"; //支付表ID
                        h+="'"+rowdata.prjPrdId+"',"; //项目产品基础信息表ID
                        h+="'"+rowdata.prjId+"'"; //项目基础信息表ID
						h+=')">'+value+'</a>';
						return h;
					}},
				{ display: '客户名称', name: 'cstNm', width: 120 , enabledSort:true},
				{ display: '拖车状态', name: 'backStsCd', width: 80, align:'center', enabledSort:true},
				{ display: '租赁物件名称', name: 'prdNm', width: 80 , enabledSort:true},
				{ display: '型号', name: 'prdMdl', width: 100, align:'center', enabledSort:true},
				{ display: '车架号', name: 'prdVin', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '';
						if(value != null && value != ""){
							h+='<a href="javascript:showOp(';
			                h+="'"+rowdata.prjId+"'";
			                h+=",'"+rowdata.prjPrdId+"'";
			                h+=')\">'+value+'</a>'; 
						}
						return h;
					}},
				

				{ display: '处置状态', name: 'dealStsCd', width: 100, align:'center', enabledSort:true},
				{ display: '处置费用', name: 'dealAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = rowdata.dealAmt / 100;
						return h;
					}},
				{ display: '评估状态', name: 'evalStatusCd', width: 100, align:'center', enabledSort:true},
				{ display: '入库时间', name: 'enterTm', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '';
						if(rowdata.isEnter == "1"){
							h+='<a  href="javascript:toDownload(';
			                h+="'"+rowdata.detailId+"'";
			                h+=",'rkd'";
			                h+=")\"><i >"+renderDate1(rowdata.enterTm)+"</i> </a>";
						}else{
							
							h = '未入库';
						}
						return h;
					}},
				{ display: '出库时间', name: 'outTm', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '';
						if(rowdata.isOut == "1"){
							h+='<a  href="javascript:toDownload(';
			                h+="'"+rowdata.detailId+"'";
			                h+=",'ckd'";
			                h+=")\"><i >"+renderDate1(rowdata.outTm)+"</i> </a>";
						}else{
							h = '未出库';
						}
						return h;
					}},
					getGridOperColumnContent()//操作列
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			checkbox:true,//列表是否有选择框
			rownumbers:true,//列表是否有行号
			//选择行事件
			onSelectRow: function(rowdata, rowid, rowobj){
				//设置当前选择的拖车主表ID和明细表ID值
				$("#tcDetailId").val(rowdata.detailId);
				$("#tcMasterId").val(rowdata.masterId);
			},
			//取消选择行事件
			onUnSelectRow : function(rowdata, rowid, rowobj){
				//清空当前选择的拖车主表ID和明细表ID值
				$("#tcDetailId").val('');
				$("#tcMasterId").val('');
			}
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
		grid.options.isSingleCheck = true;//列表是否为单选
	}
	
	//初始化Tab页签
	function initTab(){
		pageInTab = $("#pageInTab").ligerTab({
			height: 'auto',
			contextmenu: false,
			minIframeHeight: GET_minIframeHeight(),
			onAfterSelectTabItem: function(tabid) {
					//获取拖车主表ID和明细表ID供其它页面使用
					var tcDetailId = $("#tcDetailId").val();
					var tcMasterId = $("#tcMasterId").val();
					if(tabid!="tabA"){
						if(!tcDetailId || !tcMasterId){
							$.ligerDialog.SQalert({content: "请选择一条信息！", SQ_type: "warning"});
							return false; //验证不通过，不执行以下代码
						}
					}
					switch (tabid){
						case "tabB":							
							pageInTab.setTabItemSrc(tabid, "<%=path%>/ass/assTrailCarM/toFlowPage.do?tcMasterId="+tcMasterId+"&tcDetailId="+tcDetailId);
							break;
					}
				SetIframe_height();
			}
		});
		//设置页签
		$.extend(true, pageInApp, {
			pageInTab: pageInTab
		});
	};
	
	//清空按钮事件
	function clearBtnEvent(){
		$("#clearBtn").click(function(event) {
			$("#resetBtn").click();  //重置 input-text
			var form = liger.get("searchBar");
			form.setData({  //重置select等特殊表单
				"dealStsCd":" ",
				"evalStatusCd":" ",
				"isEnter":" ",
				"isOut":" "
			});
		});
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		$("#searchBtn").click(function(event) {
			var form = new liger.get("searchBar");
			var data = form.getData();
			for (name in data){
				grid.setParm(name,data[name]);
			};
			grid.reload();
		});
	}
	
	//查看支付表详情
	function payDetail(prjPrdDtlId,id,prjPrdId,prjId){
		var editFlag = true;
		Add_navTab('tab_prj_quat_prps'+id,'查看支付表','<%=path%>/project/prjprdpayschm/toAddPage.do?prjId='+prjId+'&&id='+id+'&&prjPrdDtlId='+prjPrdDtlId+'&&prjPrdId='+prjPrdId+'&&detailFlag='+editFlag);
	}
	//显示流程：流程实例ID,状态,业务主键(拖车主表ID)
    function commShowFlow(_pInstId, _audStsCd, _businessKey){
    	if(StringUtils.isEmpty(_pInstId)){
    		UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
    		return;
    	}
    	var _formUrl = "/ass/assTrailCarM/toViewPage.do?isDetail=1@@tcMasterId=";
    	var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
    	Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
	
	//导出信息
	function downloadBtnEvent(){
		var form = new liger.get("searchBar");
		var grid = liger.get("ligergrid1");
		var selectedRows = grid.getSelectedRows();
		var pkIds = new Array();
		for(var i=0;i<selectedRows.length;i++){
			var pkId = "'"+selectedRows[i].id+"'";
			pkIds[i] = pkId;
		}
        var data = form.getData();
        data["pkIds"] = JSON.stringify(pkIds);
        data["eFlag"] = "kggl";
		var wait_dialog = null;
		$.ajax({
			type: 'get',
			dataType:'json',
			url: '<%=path%>/ass/assTrailCarM/exportAssInfo.do',
			data:data,
			beforeSend:function(){
				wait_dialog=$.ligerDialog.SQalert({content: '正在导出信息...',SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					window.open(msg.data);
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			} 
		});
	}
	
	
	
	//隐藏掉操作列
    function getGridOperColumnContent(){
		var data = {
			display:'操作',
			isSort:false,
			width:250,
			align:'center',
			render:function (rowdata, rowindex, value){
				var h="";
					h+='<a class="sq-button-hasicon" href="javascript:toTrailCarHvDetail(';
	                h+="'"+rowdata.masterId+"'";
	                h+=",'"+rowdata.detailId+"'";
	                h+=",'"+rowdata.paySchId+"'";
	                h+=",'"+rowdata.paySchNo+"'";
	                h+=")\"><i class='sqBtnIco_4'></i>交接单详细</a>";
	                
	                if(rowdata.isEnter != "1"){//未入库
	                	h+='<a class="sq-button-hasicon" href="javascript:entryOrder(';
	  	                h+="'"+rowdata.masterId+"'";
	  	                h+=",'"+rowdata.detailId+"'";
	  	                h+=",'"+rowdata.paySchId+"'";
	  	                h+=",'"+rowdata.paySchNo+"'";
	  	                h+=",'"+rowdata.prjId+"'";
	  	                h+=",'entry'";
	  	                h+=")\"><i class='sqBtnIco_32'></i>入库</a>";
	                }
	                if(rowdata.isOut != "1"){//未出库
	                	h+='<a class="sq-button-hasicon" href="javascript:entryOrder(';
	 	                h+="'"+rowdata.masterId+"'";
	 	                h+=",'"+rowdata.detailId+"'";
	 	                h+=",'"+rowdata.paySchId+"'";
	 	                h+=",'"+rowdata.paySchNo+"'";
	 	                h+=",'"+rowdata.prjId+"'";
	 	                h+=",'out'";
	 	                h+=")\"><i class='sqBtnIco_32'></i>出库</a>";
	                }
	               
				return h;
			}
		};
		return data;
	}
	
	//交接单详情
	function toTrailCarHvDetail(masterId,detailId,paySchId,paySchNo){
		//回调刷新列表
		 var callback = function () {
			grid.reload();
		}; 
		var param = '&&tcMasterId='+masterId+'&&tcDetailId='+detailId+"&&crflag=detail";
		Add_navTab('trailCar'+paySchId,'拖车交接验收单','<%=path%>/ass/assTrailCarM/toWarehousePage.do?paySchId=' + paySchId + '&&paySchNo=' + paySchNo + param, callback);
		
	}
	
	//出入库交接单
	function entryOrder(tcMasterId,tcDetailId,paySchId,paySchNo,prjId,crflag){
		var param = '&&tcMasterId='+tcMasterId+'&&tcDetailId='+tcDetailId+'&&crflag='+crflag;
		param += '&&paySchId='+paySchId+'&&paySchNo='+paySchNo+'&&prjId='+prjId;
		Add_navTab('entryOrder'+tcDetailId,'车辆交接单','<%=path%>/ass/assTrailCarM/toWarehousePage.do?' + param);
	}
	//车辆配置单
	function showOp(_prjId,_prjPrdId){
	    Add_navTab("corePrcBook"+_prjPrdId, "车辆配置单", '<%=path%>/audit/audStandingBook/toCorePrcBookAddPage.do?prjPrdId='+_prjPrdId+'&proIntId='+$("#proIntId").val()+'&projectId='+_prjId+'&isDetail='+1);
	}
	function toDownload(pkId,flag){
		var title='入库单';
		if(flag == 'ckd')
			title = '出库单';
		var tabNm = "ASS_TRAIL_CAR_D";
		   $.ligerDialog.open({
             width:800,
             height: 350,
             title: title,
             url: '<%=path%>/ass/assTrailCarM/toDownload.do?tabNm='+tabNm+'&&pkId='+pkId+'&&flag='+flag
         });
	}
</script>
</body>
</html>